package com.zzb.text.controller;

import com.zzb.text.entity.Params;
import com.zzb.text.service.ParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created by ZZB on 2017/6/16.
 */
@Controller
@RequestMapping("/params")
public class ParamsController {
    @Autowired
    private ParamsService paramsService;

    @RequestMapping("/index")
    public String list(Model model){
        List<Params> list = paramsService.list();
        model.addAttribute("list",list);
        return "/params/index";
    }

    @RequestMapping("/form")
    public String form(Params params, Model model){
        String id = params.getId();
        if(id!=null){
            params = paramsService.get(id);
        }
        model.addAttribute("params",params);
        return "/params/form";
    }

    @RequestMapping("/save")
    public String save(Params params){
        paramsService.save(params);
        return "redirect:/params/index";
    }

    @RequestMapping("/delete")
    public String delete(String id){
        paramsService.delete(id);
        return "redirect:/params/index";
    }

}
